<?php
namespace app\a\controller;
use qiniu\Qn;
use think\facade\Db;
class Common extends Base{

    //修改 配置表数据
    public function edit_config_list(){
        $param = input("");
        foreach($param['data'] as $k=>$v){
            $bool = Db::table('an_config')->where('id', $v['id'])->update([
                'up_time'=>time(),
                'value'=>$v['value'],
                'sort'=>$v['sort'],
                'title'=>$v['title'],
            ]);
        }
        $this->logData('修改系统设置');
        return json($this->info);
    }

    //添加 系统配置
    public function add_config_list(){
        $param = input('');
        Db::table('an_config')->insert([
            'create_time'=>time(),
            'up_time'=>time(),
            'tabs_type'=>$param['tabs_type'],
            'key'=>$param['key'],
            'data_type'=>$param['data_type'],
            'value'=>$param['value'],
            'title'=>$param['title'],
            'notes'=>$param['notes'],
            'sort'=>$param['sort'],
            'arr'=>$param['arr'],
        ]);
        $this->logData('新增系统设置');
        return json($this->info);
    }

    //检查key是否唯一
    public function check_config_key(){
        $param = input("");
        $this->info['data'] = Db::table('an_config')->where('key',$param['key'])->find();
        return json($this->info);
    }

    //删除配置项
    public function del_config(){
        $param = input("");
        Db::table('an_config')->where('id',$param['id'])->delete();
        return json($this->info);
    }

    //分类列表
    public function type_list_data(){
        $param = input("");
        $listData = Db::table('an_type')
        ->where('type', $param['type'])
        ->page($param['page'],$param['limit'])
        ->order('sort', 'desc')
        ->select()
        ->toArray(); 
        $this->info['data'] = $listData;
        $this->info['total'] = Db::table('an_type')
        ->where('type', $param['type'])
        ->count();
        return json($this->info);
    }
}
